<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>aperture</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const aperture = (arr, n) =>
            n > arr.length ? [] : arr.slice(n - 1).map((v, i) => arr.slice(i, i + n));
        console.log(aperture([1, 2, 3, 4], 2)); // [[1, 2], [2, 3], [3, 4]]
        console.log(aperture([1, 2, 3, 4], 3)); // [[1, 2, 3], [2, 3, 4]]
        console.log(aperture([1, 2, 3, 4], 5)); // []
    </script>
</body>

</html>